home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / overview / win2maccountersamples / 5. counterprint / source / ccounterapp.cp next >
Encoding:
Text File  |  2000-09-28  |  3.7 KB  |  132 lines

  1. /*
  2.     File:        CCounterApp.cp
  3.  
  4.     Contains:    Sample code to accompany Chapter 12 of 
  5.                 "An Introduction to Macintosh Programming for Windows Programmers".
  6.                 
  7.     Written by:    Worldwide Developer Technical Support
  8.  
  9.     Copyright:    1999 Apple Computer, Inc., All Rights Reserved
  10.  
  11.       You may incorporate this sample code into your applications without
  12.       restriction, though the sample code has been provided "AS IS" and the
  13.       responsibility for its operation is 100% yours.  However, what you are
  14.       not permitted to do is to redistribute the source as "DSC Sample Code"
  15.       after having made changes. If you're going to re-distribute the source,
  16.      we require that you make it clear in the source that the code was
  17.     descended from Apple Sample Code, but that you've made changes.
  18.     
  19. */
  20.  
  21. #include "CCounterApp.h"
  22. #include "CounterConstants.h"
  23. #include "CCounterDocument.h"
  24. #include <LSIOUXAttachment.h>
  25. #include <iostream.h>
  26.  
  27. #include <LStaticText.h>
  28. #include <LIconPane.h>
  29.  
  30. #include <LGrowZone.h>
  31. #include <LWindow.h>
  32. #include <PP_Messages.h>
  33. #include <PP_Resources.h>
  34. #include <PPobClasses.h>
  35. #include <UDrawingState.h>
  36. #include <UMemoryMgr.h>
  37. #include <URegistrar.h>
  38.  
  39. #include <UControlRegistry.h>
  40. #include <UGraphicUtils.h>
  41. #include <UEnvironment.h>
  42.  
  43. #ifndef __APPEARANCE__
  44. #include <Appearance.h>
  45. #endif
  46.  
  47. #include <Sound.h>
  48. #include <ToolUtils.h>
  49.  
  50. // ===========================================================================
  51. int main()
  52. {
  53.     SetDebugThrow_(debugAction_Alert);
  54.     SetDebugSignal_(debugAction_Alert);
  55.     InitializeHeap(3);                    // allocate 3 Master Pointer blocks
  56.     UQDGlobals::InitializeToolbox(&qd);
  57.     UEnvironment::InitEnvironment();
  58.     new LGrowZone(20000);            // For low memory situations.
  59.     CCounterApp    theApp;            // stack allocation
  60.     theApp.Run();
  61.     return 0;
  62. }
  63.  
  64. // ---------------------------------------------------------------------------
  65. CCounterApp::CCounterApp()
  66. {
  67.     if ( UEnvironment::HasFeature( env_HasAppearance ) ) {
  68.         ::RegisterAppearanceClient();
  69.     }
  70.     RegisterAllPPClasses();    // functions to create core PowerPlant classes
  71.     UControlRegistry::RegisterClasses();    // Appearance Manager/GA classes
  72.     RegisterClass_(LIconPane);
  73.     AddAttachment(new LSIOUXAttachment);    // Use SIOUX Attachment
  74. }
  75.  
  76.  
  77. // ---------------------------------------------------------------------------
  78. CCounterApp::~CCounterApp()
  79. {
  80. }
  81.  
  82. // ---------------------------------------------------------------------------
  83. //    This function lets you do something when the application starts up
  84. //    without a document.
  85. void
  86. CCounterApp::StartUp()
  87. {
  88.     ObeyCommand(cmd_New, nil);
  89. }
  90.  
  91. // ---------------------------------------------------------------------------------
  92. void
  93. CCounterApp::OpenDocument(FSSpec* inMacFSSpec )
  94. {
  95.     LDocument* theDoc = LDocument::FindByFileSpec(*inMacFSSpec);
  96.     if (theDoc != nil) {                // Document is already open
  97.         theDoc->MakeCurrent();            // Make it the current document
  98.     } else {                            // Make a new Document
  99.         theDoc = new CCounterDocument(this, inMacFSSpec);
  100.     }
  101. }
  102.  
  103. // ---------------------------------------------------------------------------------
  104. LModelObject*
  105. CCounterApp::MakeNewDocument()
  106. {
  107.     FSSpec* spec = nil;
  108.     return new CCounterDocument(this, spec);
  109. }
  110.  
  111. // ---------------------------------------------------------------------------------
  112. void
  113. CCounterApp::ChooseDocument()
  114. {
  115.     UDesktop::Deactivate();
  116.     SFTypeList            theTypeList = {kDocType};
  117.     StandardFileReply    theReply;
  118.     ::StandardGetFile( nil, 1, theTypeList, &theReply );
  119.     UDesktop::Activate();
  120.     if (theReply.sfGood) {                // if not canceled
  121.         SendAEOpenDoc(theReply.sfFile);    // send AppleEvent to open the document
  122.     }
  123. }
  124.  
  125. // ---------------------------------------------------------------------------------
  126. void
  127. CCounterApp::PrintDocument(FSSpec* inMacFSSpec )
  128. {
  129.     CCounterDocument* theDocument = new CCounterDocument(this, inMacFSSpec);
  130.     theDocument->DoPrint();
  131. }
  132.